package com.refactordemo.entity;

import java.util.Enumeration;
import java.util.Vector;

/**
 * 顾客类
 */

class Customer {

    //顾客名字
    private String _name;
    //使用vector集合存储租金对象
    private Vector _rentals = new Vector();

    //重载构造方法
    public Customer(String name) {
        this._name = name;
    }

    //添加租金对象到租金集合中
    public void addRental(Rental arg) {
        _rentals.addElement(arg);
    }

    public String getName() {
        return _name;
    }

    //订单说明方法
    public String statement() {
        double totalAmount = 0;//总价
        int frequentRenterPoints = 0;//积分
        //建立枚举接收租赁记录中的元素
        Enumeration rentals = _rentals.elements();
        String result = "租赁记录：" + getName() + "\n";//订单说明
        //遍历租赁记录
        while (rentals.hasMoreElements()) {
            double thisAmount = 0;//总价
            //获取每一个租赁对象
            Rental each = (Rental) rentals.nextElement();

            //确定不同顾客的价钱
            switch (each.getMovie().getPriceCode()) {
                case Movie.REGULAR://如果是常客
                    thisAmount += 2;
                    if (each.getDaysRented() > 2) //如果租赁时间大于2
                        thisAmount += (each.getDaysRented() - 2) * 1.5;
                    break;
                case Movie.NEW_RELEASE://如果是新人
                    thisAmount += each.getDaysRented() * 3;
                    break;
                case Movie.CHILDRENS://如果是小孩
                    thisAmount += 1.5;
                    if (each.getDaysRented() > 3)
                        thisAmount += (each.getDaysRented() - 3) * 1.5;
                    break;
            }

            //增加常客积分
            frequentRenterPoints++;
            //额外的奖金为两天的新发行的租赁
            if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) && each.getDaysRented() > 1)
                frequentRenterPoints++;
        }
        //请给出租金的数字
        result += "需缴纳" + String.valueOf(totalAmount) + "\n";
        result += "你获取了" + String.valueOf(frequentRenterPoints) + "积分";
        return result;

    }


}
